<%@ page language="java" contentType="text/html;charset=UTF-8" %><%@ include file="../../inc/global.jsp" 
%>
<!doctype html>
<html>
<head>
<title>${adminGlobalConfig.name}</title>
<%@include file="../head.jsp" %>
<style type="text/css">
.pause, .sending, .over, .ok {display:block; padding:3px 11px; margin:11px 0px;text-align:center; cursor:pointer;}
.pause {background:#e6e6e6; color:#333;}
.sending {background:#ff6600; color:#fff;}
.over {background:#ff0000; color:#fff;}
.ok {background:#3FA156; color:#fff;}
#ajaxData h4 {margin: 7px auto 3px 7px;}
</style>
<script type="text/javascript">
$(function(){
	var _id;
	var b;
	var e;
	var id;
	var s;
	function getStatus() {
		$.ajax({
			type:'GET'
			, url:'/a/ajax/customer/msg/status'
			, data:{id:id}
			, success:function(data){
				var json=$.parseJSON(data);
				var txt='<h3>发送状态统计</h3>';
				txt+='<h4>准备发送：'+json.data.already+'</h4>'
				txt+='<h4>正在发送：'+json.data.sending+'</h4>'
				txt+='<h4>发送成功：'+json.data.succeed+'</h4>'
				txt+='<h4>发送失败：'+json.data.failed+'</h4>'
				$('#status').html(txt);
				if(json.data.sending>0) {
					$('#someBtn').html('<input type="button" name="button" id="continueSend" value="继续发送" />');
				}
			}
		});
	};
	var bg, dt;
	function hide() {
		aju.removeAll([ dt, bg, $('.tip-yellow') ]);
		$('#ajaxClose').remove();
	};
	$(document).keydown(function(){
		if(event.keyCode == KEY.ESC) {
			hide();
		}
	});
	$('td span').bind('click', function() {
		var btn = this;
		_id = $(this).attr('id');
		b = _id.indexOf('_') + 1;
		e = _id.lastIndexOf('_');
		id = _id.substring(b, e);
		s = _id.substring(e + 1);
		var url = '/a/ajax/customer/msg/btn';
		$.ajax({
			type : 'GET',
			url : url,
			data : {
			id : id,
			s : s
			},
			success : function(data) {
				bg = aju.ajaxBg(function() {
					aju.setOffsetDown(200);
					aju.setOffsetRight(10);
					dt = aju.ajaxData().css({
						'width' : '600',
						'height' : '260'
					});
					dt.html(data);
					aju.positionCenter(dt);
					getStatus();
					// 显示关闭按钮并绑定关闭事件
					aju.ajaxClose(dt).click(function() {
							hide();
					});
					$('#send').click(function(){
						$(this).attr('disabled','disabled');
						var url='/a/ajax/customer/msg/do?id='+id+'&act=1';
						$.ajax({
							type:'POST'
							,url:url
							,data:{id:id}
							,success:function(data){
								alert('操作成功！');
								var td = $(btn).parent();
								$(btn).remove();
								$(td).html('<span class="ok" id="ok_'+id+'_4">完成</span>');
								hide();
							}
						});
					});
					$('#continueSend').click(function(){
						$(this).attr('disabled','disabled');
						var url='/a/ajax/customer/msg/do?id='+id+'&act=2';
						$.ajax({
							type:'POST'
							,url:url
							,data:{id:id}
							,success:function(data){
								alert('操作成功！');
								hide();
								var td = $(btn).parent();
								$(btn).remove();
								$(td).html('<span class="ok" id="ok_'+id+'_4">完成</span>');
							}
						});
					});
					$('#anewSend').click(function(){
						$(this).attr('disabled','disabled');
						var url='/a/ajax/customer/msg/do?id='+id+'&act=3';
						$.ajax({
							type:'POST'
							,url:url
							,data:{id:id}
							,success:function(data){
								alert('操作成功！');
								hide();
								var td = $(btn).parent();
								$(btn).remove();
								$(td).html('<span class="ok" id="ok_'+id+'_4">完成</span>');
							}
						});
					});
					$('#cancel').click(function(){
						$(this).attr('disabled','disabled');
						var url='/a/ajax/customer/msg/do?id='+id+'&act=4';
						$.ajax({
							type:'POST'
							,url:url
							,data:{id:id}
							,success:function(data){
								alert('操作成功！本任务已经取消不再发送！');
								hide();
								var td = $(btn).parent();
								$(btn).remove();
								$(td).html('<span class="over" id="over_'+id+'_3">强制结束</span>');
							}
						});
					});
				});
			}
		});
	});
});
//
function delJob(id) {
	function hide() {
		aju.removeAll([ dt, bg, $('.tip-yellow') ]);
		$('#ajaxClose').remove();
	};
	$(document).keydown(function(){
		if(event.keyCode == KEY.ESC) {
			hide();
		}
	});
	var bg, dt;
	var url='/a/ajax/customer/msgJob/delConfirm';
	$.ajax({
		type:'GET'
		,url:url
		,data:{id:id}
		,success:function(data){
			bg = aju.ajaxBg(function() {
				aju.setOffsetDown(200);
				aju.setOffsetRight(10);
				dt = aju.ajaxData().css({
					'width' : '600',
					'height' : '260'
				});
				dt.html(data);
				aju.positionCenter(dt);
				// 显示关闭按钮并绑定关闭事件
				aju.ajaxClose(dt).click(function() {
						hide();
				});
				$('#delJob').click(function(){
					$(this).attr('disabled','disabled').val('删除中...');
					var url='/a/ajax/customer/msgJob/del?r=' + new Date().getTime();
					//alert(id);
					$.ajax({
						type:'POST'
						,url:url
						,data:{id:id}
						,success:function(data){
							//(data);
							$('#line_'+id).remove();
							alert('操作成功！');
							hide();
						}
					});
				});
			});
		}
	});
}
</script>
</head>
<body>
<div class="wrapper">
<%@include file="../header.jsp" %>
<div class="body">
<div class="list">
<div class="listnav">
</div>
<table>
<thead>
<tr>
<th>任务名称</th>
<th>内容</th>
<th>创建时间</th>
<th>结束时间</th>
<th>总数</th>
<th>成功</th>
<th>失败</th>
<th>任务状态</th>
<th style="text-align:center; width:38px;">详情</th>
<th style="text-align:center; width:38px;">删除</th>
</tr>
</thead>
<c:if test="${empty(msgJobs)}">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>暂无数据...</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</c:if>
<tbody>
<c:forEach var="job" items="${msgJobs}" varStatus="s">
<c:if test="${(s.index % 2) != 0}">
<tr class="trbg" id="line_${job.id}">
</c:if>
<c:if test="${(s.index % 2) == 0}">
<tr id="line_${job.id}">
</c:if>
<td>${job.name}</td>
<td>${job.content}</td>
<td><fmt:formatDate pattern="yy-MM-dd hh:mm:ss" value="${job.addTime}" /></td>
<td><fmt:formatDate pattern="yy-MM-dd hh:mm:ss" value="${job.endTime}" /></td>
<td>${job.total}</td>
<td>${job.succeed}</td>
<td>${job.failed}</td>
<td>
<c:if test="${job.status==0}">
<span class="already" id="already_${job.id}_0">准备发送</span>
</c:if>
<c:if test="${job.status==1}">
<span class="sending" id="sending_${job.id}_1">发送中</span>
</c:if>
<c:if test="${job.status==2}">
<span class="pause" id="pause_${job.id}_2">暂停</span>
</c:if>
<c:if test="${job.status==3}">
<span class="over" id="over_${job.id}_3">强制结束</span>
</c:if>
<c:if test="${job.status==4}">
<span class="ok" id="ok_${job.id}_4">完成</span>
</c:if>
</td>
<td style="text-align:center;">
<a href="/a/customer/msgJob?id=${job.id}">详情</a>
</td>
<td style="text-align:center;">
<a href="###" onclick="javascript:delJob('${job.id}')">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
${pagination}
</div>
<div class="sidebarMenu">
<ul>
<li><a href="/a/customer/msgJobs/create">新建群发任务</a></li>
</ul>
</div>
<div class="sidebar">
<div class="prop-item">
</div>
</div>
<!--  -->
</div>
</div>
</body>
</html>